<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加</title>
    <script src="axios.min.js"></script>
    <style>
        .add {
            width: 500px;
            height: 150px;
            position: relative;
        }
        
        input {
            width: 200px;
            height: 25px;
            margin-top: 10px;
            margin-left: 40px;
        }
        
        button {
            width: 50px;
            height: 25px;
            margin-left: 50px;
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <div class="add">
        <input type="text" placeholder="名称">
        <input type="text" placeholder="价格">
        <input type="text" placeholder="描述"><br>
        <button>添加</button>
    </div>
    <script>
        let oInput = document.querySelectorAll('input');
        let btn = document.querySelector('button');
        btn.onclick = function() {
            let oName = oInput[0].value;
            let price = oInput[1].value;
            let describe = oInput[2].value;
            axios({
                method: 'post',
                url: 'http://localhost:3000/data',
                data: {
                    mz: oName,
                    jg: price,
                    js: describe
                }
            }).then((data) => {
                console.log(data)
                alert('添加成功')
                location.href = './index.html'
            })
        }
    </script>
</body>

</html>